package com.springtest.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

import com.fasterxml.jackson.annotation.JsonView;
import com.springtest.demo.model.ResultEntity;
import com.springtest.demo.model.Student;
import com.springtest.demo.serices.StudentService;
import com.springtest.demo.views.StudentView;

@Controller
@RequestMapping("/student")
public class StudentController {
	@Resource(name="studentService")
	private StudentService  studentService;
	
	@JsonView(StudentView.StudentAll.class)
	@RequestMapping(value="/saveStu", method=RequestMethod.POST)
	public @ResponseBody ResultEntity saveStu(@RequestBody Student stu ){
		return studentService.saveStu(stu);

		
	}
	
	@JsonView(StudentView.StudentAll.class)
	@RequestMapping(value="/deleteStu/{id}", method=RequestMethod.GET)
	public @ResponseBody ResultEntity deleteStu(@PathVariable int id){
		return studentService.deleteStu(id);
		
	}
	
	@JsonView(StudentView.StudentNameAndPass.class)
	@RequestMapping(value="/updateStu", method=RequestMethod.POST)
	public @ResponseBody ResultEntity updateStu(@RequestBody Student stu ){
	
		return studentService.updateStu(stu);
	}
	
	@JsonView(StudentView.StudentNameAndPass.class)
	@RequestMapping(value="/listStuByParam", method=RequestMethod.GET)
	public @ResponseBody ResultEntity listStuByParam(String param,String value){
		
		return studentService.listStuByParam(param, value);
	}
	
	
	@JsonView(StudentView.StudentNameAndPass.class)
	@RequestMapping(value="/listStu", method=RequestMethod.GET)
	public @ResponseBody ResultEntity listStu(){
		
		return studentService.listStu();
	}
	
}
